package com.hdkj.educms.controller;


import com.hdkj.commonutils.R;
import com.hdkj.educms.entity.CmsBanner;
import com.hdkj.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 *
 * @author 贾佩雨
 * @since 2022-05-12
 */
@RestController
@RequestMapping("/educms/banneradmin")
//@CrossOrigin
public class BanneradminController {

    @Autowired
    private CrmBannerService bannerService;
//分页查询
    @PostMapping("{page}/{limit}")
    public R pagebanner(@PathVariable Long page ,@PathVariable Long limit){
        Page<CmsBanner>bannerPage =new Page<>(page,limit);
        bannerService.page(bannerPage,null);
        return R.ok().data("total",bannerPage.getTotal()).data("rows",bannerPage.getRecords());
    }

    @PostMapping("addbanner")
    public R addbanner(CmsBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }

    @PostMapping("updatebanner")
    public R upbanner(CmsBanner crmBanner){
        bannerService.updateById(crmBanner);
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R delbanner(String id){
        bannerService.removeById(id);
        return R.ok();
    }

}

